//black jack


enum suit {
	club = 1 "Club",
	diamond = 2 "Diamond",
	heart = 3 "Heart",
	spade = 4 "Spade"
};

enum num {
	N1 = 11 "A",
	N2 = 2 "2",
	N3 = 3 "3",
	N4 = 4 "4",
	N5 = 5 "5",
	N6 = 6 "6", 
	N7 = 7 "6",
	N8 = 8 "7",
	N9 = 9 "8",
	N0 = 10 "10",
	NJ = 10 "Jack",
	NQ = 10 "Queen",
	NK = 10 "King"
};

enum player {
	dealer "dealer",
	player1 "player1"	
};

enum choices {
	hit "hit",
	stay "stay"
};

enum go_on {
	go_on "continue"
};

enum card <suit, num>;
cont <enum card> deck;

cont <enum card> hand_player;
cont <enum card> hand_dealer;

enum card draw;
int player_point;
int dealer_point;
int screen;

enum choices selection;
enum go_on go;

event entry {
	call init;
	input(player1, go);

	call init_deal;
	call check_black_jack;
	call player_turn;

	input(player1, go);

	call dealer_turn;
	input(player1, go);

	call check_result;
	input(player1, go);
}

event init {
	fill(deck);
	shuffle(deck);
	shuffle(deck);
	shuffle(deck);
}

event init_deal {
	enum num temp;

	player_point = 0;
	dealer_point = 0;
	screen = 0;

	screen = 0;
	output(0, "Dealer's Draw");

	call draw_card;
	temp = extract(draw, 1);
	dealer_point = dealer_point + value(temp);
	call draw_card;
	temp = extract(draw, 1);
	dealer_point = dealer_point + value(temp);

	output(0, " ");

	screen = 1;
	output(0, "Player's Draw");


	call draw_card;
	temp = extract(draw, 1);
	player_point = player_point + value(temp);

	call draw_card;
	temp = extract(draw, 1);
	player_point = player_point + value(temp);
}

event draw_card{
	draw = peek(deck, 1);
	shuffle(deck);
	shuffle(deck);
	shuffle(deck);
	shuffle(deck);
	shuffle(deck);
	shuffle(deck);
	shuffle(deck);
	output(screen, "$draw");
}

event check_black_jack {
	
	if(dealer_point == 21) {
		output(0, "Dealer's Black Jack. Winner: Dealer");
		return;
	}

	if(player_point == 21) {
		output(0, "Player's Black Jack. Winner: Player");
		return;
	}
}

event player_turn {
	enum num temp;

	while (player_point <= 21) {
		output(1, "Your current hand point:");
		output(1, "$player_point");
		input(player1, selection);
		if(selection == hit) {
			screen = 1;
			call draw_card;
			temp = extract(draw, 1);
			player_point = player_point + value(temp);
		} else {
			break;
		}
	}

	if(player_point > 21) {
		output(0, "Player lose with flush");
		return;
	}
}

event dealer_turn {
	enum num temp;
	int i;

	while (dealer_point <= 15) {
		screen = 0;
		call draw_card;
		temp = extract(draw, 1);
		i = value(temp);
		dealer_point = dealer_point + value(temp);
	}

	if(dealer_point > 21) {
		output(0, "Dealer lose with flush");
		return;
	}
}

event check_result {
	output(0, "player point");
	output(0, "$player_point");
	output(0, "dealer point");
	output(0, "$dealer_point");

	if (player_point > dealer_point) {
		output(0, "Winner, Player");
	} else {
		output(0, "Winner, Dealer");
	}
}

